﻿using System;
using System.Collections.Generic;
using Assets.HSVPicker;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

// Token: 0x02000033 RID: 51
public class ColorPresets : MonoBehaviour
{
	// Token: 0x06000111 RID: 273 RVA: 0x0000C799 File Offset: 0x0000A999
	private void Awake()
	{
		this.picker.onValueChanged.AddListener(new UnityAction<Color>(this.ColorChanged));
	}

	// Token: 0x06000112 RID: 274 RVA: 0x0000C7B8 File Offset: 0x0000A9B8
	private void Start()
	{
		this._colors = ColorPresetManager.Get(this.picker.Setup.PresetColorsId);
		if (this._colors.Colors.Count < this.picker.Setup.DefaultPresetColors.Length)
		{
			this._colors.UpdateList(this.picker.Setup.DefaultPresetColors);
		}
		this._colors.OnColorsUpdated += this.OnColorsUpdate;
		this.OnColorsUpdate(this._colors.Colors);
	}

	// Token: 0x06000113 RID: 275 RVA: 0x0000C84C File Offset: 0x0000AA4C
	private void OnColorsUpdate(List<Color> colors)
	{
		for (int i = 0; i < this.presets.Length; i++)
		{
			if (colors.Count <= i)
			{
				this.presets[i].SetActive(false);
			}
			else
			{
				this.presets[i].SetActive(true);
				this.presets[i].GetComponent<Image>().color = colors[i];
			}
		}
		this.createPresetImage.gameObject.SetActive(colors.Count < this.presets.Length);
	}

	// Token: 0x06000114 RID: 276 RVA: 0x0000C8D8 File Offset: 0x0000AAD8
	public void CreatePresetButton()
	{
		this._colors.AddColor(this.picker.CurrentColor);
	}

	// Token: 0x06000115 RID: 277 RVA: 0x0000C8F0 File Offset: 0x0000AAF0
	public void PresetSelect(Image sender)
	{
		this.picker.CurrentColor = sender.color;
	}

	// Token: 0x06000116 RID: 278 RVA: 0x0000C903 File Offset: 0x0000AB03
	private void ColorChanged(Color color)
	{
		this.createPresetImage.color = color;
	}

	// Token: 0x04000214 RID: 532
	public ColorPicker picker;

	// Token: 0x04000215 RID: 533
	public GameObject[] presets;

	// Token: 0x04000216 RID: 534
	public Image createPresetImage;

	// Token: 0x04000217 RID: 535
	private ColorPresetList _colors;
}
